using System;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.ObjCRuntime;
using Cocos2D;

namespace Tester
{
	public class MenuScene : Scene
	{
		private Sprite _sprite;
		private float _xSpeed;
		private float _ySpeed;
		
		public MenuScene()
		{
			_xSpeed = 100.0f;
			_ySpeed = 50.0f;
			
			_sprite = Sprite.SpriteWithFile("sprite.png");
			_sprite.Position = new PointF(240.0f, 160.0f);
			
			this.AddChild(_sprite, 0);
			this.AddChild(new MenuLayer(), 1);
			
			this.Schedule(new Selector("updateSprite:"), 1.0f / 60.0f);
		}
		
		[Export("updateSprite:")]
		public void UpdateSprite(float delta)
		{
			var x = _sprite.Position.X;
			var y = _sprite.Position.Y;
			
			if (x >= 420.0f || x <= 100.0f)
				_xSpeed = -_xSpeed;
			
			if (y >= 280.0f || y <= 100.0f)
				_ySpeed = -_ySpeed;
			
			x += _xSpeed * delta;
			y += _ySpeed * delta;
			
			_sprite.Position = new PointF(x, y);
		}
	}
	
	public class MenuLayer : Layer
	{
		public MenuLayer()
		{
			MenuItemFont.FontSize = 20;
			MenuItemFont.FontName = "Helvetica";
			
			var start = MenuItemFont.ItemFromString("Start Game", (NSObject sender) => {
				Console.WriteLine("start game");
			});
			
			var help = MenuItemFont.ItemFromString("Help", (NSObject sender) => {
				Console.WriteLine("help");
			});
			
			var menu = Menu.MenuWithItems(start, help);
			menu.AlignItemsVertically();
			
			this.AddChild(menu);
		}
	}
}
